import os
import typing
from pydantic_settings import BaseSettings
from pydantic import  field_validator


class Settings(BaseSettings):
    VERSION: str = "0.1.0"
    APP_TITLE: str = "小程序管理系统"
    PROJECT_NAME: str = "小程序管理系统"
    APP_DESCRIPTION: str = "小程序管理系统"
    APP_IP: str = "https://mini.yanjin.pro/"

    CORS_ORIGINS: typing.List = ["*"]
    CORS_ALLOW_CREDENTIALS: bool = True
    CORS_ALLOW_METHODS: typing.List = ["*"]
    CORS_ALLOW_HEADERS: typing.List = ["*"]

    DEBUG: bool = True
    PROJECT_ROOT: str = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
    BASE_DIR: str = os.path.abspath(os.path.join(PROJECT_ROOT, os.pardir))
    LOGS_ROOT: str = os.path.join(BASE_DIR, "app/log")
    SECRET_KEY: str = "3488a63e1765035d386f05409663f55c83bfae3b3c61a932744b20ad14244dcf"  # openssl rand -hex 32
    JWT_ALGORITHM: str = "HS256"
    JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 365  # 100年
    TORTOISE_ORM: dict = {
        "connections": {
            "mysql": {
                'engine': 'tortoise.backends.mysql',
                "credentials": {
                    "host": "115.29.202.65",
                    "port": "3306",
                    "user": "mini",
                    "password": "3b3379d8a4",
                    "database": "mini",
                },
            }
        },
        "apps": {
            "models": {
                "models": ["app.models", "aerich.models"],
                "default_connection": "mysql",
            },
        },
        "use_tz": False,
        "timezone": "Asia/Shanghai",
    }
    REDIS:str = "redis://localhost:6379/2"
    DATETIME_FORMAT: str = "%Y-%m-%d %H:%M:%S"
    DATE_FORMAT: str = "%Y-%m-%d"
    ALLOWED_IMAGES: typing.List = ['png', 'jpg', 'jpeg', 'gif','webp']
    ALLOWED_EXTENSIONS: typing.List = ['png', 'jpg', 'jpeg', 'gif', 'mp3', 'mp4', 'xlsx', 'xls', 'csv', 'pdf', 'doc', 'docx','webp']
    UPLOAD_FOLDER:str = "app/upload"
    EXCEL_FOLDER:str = "app/upload/excel"
    MYSQL_BAK_FOLDER: str = "app/upload/mysqlbak"
    GO_TYPE: typing.List = ['无', '跳转文章', '跳转商品', '跳转专题', '自定义']

    CUSTOMER_PLATFORM: typing.List = ['', '小程序', 'IOS', '安卓','散客','老带新','抖音','大众点评','朋友推荐','美团','小红书','其他渠道']
    CUSTOMER_SEX: typing.List = ['', '男', '女']
    CONTENT_TYPE: typing.List = ['', '图文', '视频']

    # 微信小程序的 AppID 和 AppSecret
    WEICHAT_APP_ID:str = "wxfbe78b6d96c31925" ##小程序id
    WEICHAT_APP_SECRET:str = "50e993cfca43ffc83fc408ef5e2cc8ea" ##小程序密钥
    WEICHAT_MCHID: str = "1532934351" ##商户号
    WEICHAT_CERT_PATH: str = "app/controllers/orders/pem/apiclient_cert.pem"
    WEICHAT_KEY_PATH: str = "app/controllers/orders/pem/apiclient_key.pem"
    WEICHAT_PUBLIC_KEY: str = "app/controllers/orders/pem/pub_key.pem"
    WEICHAT_NOTIFY: str = "https://mini.yanjin.pro/api_mini/mini_orders/orders/wechat/notify"
    WEICHAT_API_V3_KEY: str = "dc7fc22abbd182b4872abdbed63d4936" ##apiv3密钥，直接改官方的
    WEICHAT_NO: str = "6F9FDA38D357E4D2584A999A2FE9E6C762383FE3" ##商户API证书序列号
    WEICHAT_PUBLIC_KEYID:str = "PUB_KEY_ID_0115329343512025030600219100002022" ##公钥ID

    # 腾讯云 COS 配置
    COS_SECRET_ID: str = 'AKIDT2f7Uo26ye7GLH5lGaihUTK2Yy89ykKl'  # 替换为你的 SecretId
    COS_SECRET_KEY: str = 'LUVKzhAbzGNJE1sb7QabS8rCPSNJ9tUA'  # 替换为你的 SecretKey
    COS_REGION: str = 'ap-nanjing'  # 替换为你的存储桶地域
    COS_BUCKET: str = 'mini-1329442127'  # 替换为你的存储桶名称


    APPOINTMENT_CITY: typing.List[str] = ["","上海","杭州","南京"]

    @field_validator('APPOINTMENT_CITY', mode='before')
    def parse_appointment_city(cls, v):
        # 如果 v 是字符串，使用逗号分隔成列表
        if isinstance(v, str):
            return [item.strip() for item in v.split(',')]  # 去掉前后空格
        return v

    APPOINTMENT_INSTRUMENT: typing.List = ['无', '皮秒', '超皮秒', '星耀']
    APPOINTMENT_PROJECT: typing.List = ['', '项目类别1', '项目类别2', '项目类别3']
    APPOINTMENT_T: typing.List = ['', '项目预约', '美学预约', '沙龙预约']
    APPOINTMENT_TYPE: typing.List = ['', '操作预约', '睡眠预约']
    APPOINTMENT_DESIGNER_TYPE: typing.List = ['', '助理', '美学', '技师']
    APPOINTMENT_DOCTOR_TYPE: typing.List = ['', '护理']
    APPOINTMENT_STATUS: typing.List = ["待审核","通过","未通过", "已取消"]

    ORDERS_STATUS: typing.List = ["待付款", "已付款", "已取消", "申请退款中", "已退款"]
    EXPRESS_STATUS: typing.List = ["待发货", "已发货", "部分发货"]
    EXPRESS_STATUS_DD: typing.List = ["待接待", "已接待", "接待中"]
    GOODS_TYPE: typing.List = ['',"项目","产品","储值","套餐卡"]
    COUPONS_TYPE: typing.List = ['', "手动发放", "商品生成", "抽奖获得","分享获得"]
    DRAWROLE_TYPE: typing.List = ['无奖品', "", "优惠券", "商品", "积分"]

    JOBS_TYPE: typing.List = ['', '循环任务', '定时任务']
    ORDER_TIMEOUT:int = 5

    SAAS_CONSUMABLES_TYPE: typing.List = ['', '普通耗材', '仪器耗材', '其他耗材']

    # class Config:
    #     env_file = "app/settings/.env"  # 指定 .env 文件路径

settings = Settings()
